home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 742 / rkrm_lib2 / rkrm_lib2.lha / Exec_Library / Ports / port1.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  4KB  |  96 lines

  1. ;/* port1.c - Execute me to compile with SAS C 5.10
  2. LC -b1 -cfistq -v -y -j73 port1.c
  3. Blink FROM LIB:c.o,port1.o TO port1 LIBRARY LIB:LC.lib,LIB:Amiga.lib
  4. quit ;
  5.  
  6. port1.c - port and message example, run at the same time as port2.c
  7.  
  8.  
  9. Copyright (c) 1992 Commodore-Amiga, Inc.
  10.  
  11. This example is provided in electronic form by Commodore-Amiga, Inc. for
  12. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  13. published by Addison-Wesley (ISBN 0-201-56774-1).
  14.  
  15. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  16. information on the correct usage of the techniques and operating system
  17. functions presented in these examples.  The source and executable code
  18. of these examples may only be distributed in free electronic form, via
  19. bulletin board or as part of a fully non-commercial and freely
  20. redistributable diskette.  Both the source and executable code (including
  21. comments) must be included, without modification, in any copy.  This
  22. example may not be published in printed form or distributed with any
  23. commercial product.  However, the programming techniques and support
  24. routines set forth in these examples may be used in the development
  25. of original executable software products for Commodore Amiga computers.
  26.  
  27. All other rights reserved.
  28.  
  29. This example is provided "as-is" and is subject to change; no
  30. warranties are made.  All use is at your own risk. No liability or
  31. responsibility is assumed.
  32. */
  33.  
  34. #include <exec/types.h>
  35. #include <exec/ports.h>
  36. #include <dos/dos.h>
  37. #include <clib/exec_protos.h>
  38. #include <clib/alib_protos.h>
  39. #include <stdio.h>
  40.  
  41. #ifdef LATTICE
  42. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL-C handling */
  43. int chkabort(void) {return(0);}
  44. #endif
  45.  
  46. struct XYMessage {
  47.     struct Message xym_Msg;
  48.     WORD           xy_X;
  49.     WORD           xy_Y;
  50. };
  51.  
  52. void main(int argc, char **argv)
  53. {
  54.     struct MsgPort *xyport;
  55.     struct XYMessage *xymsg;
  56.     ULONG portsig, usersig, signal;
  57.     BOOL ABORT = FALSE;
  58.  
  59.     if (xyport = CreatePort("xyport", 0))
  60.     {
  61.         portsig = 1 << xyport->mp_SigBit;       /* Give user a `break' signal. */
  62.         usersig = SIGBREAKF_CTRL_C;
  63.  
  64.         printf("Start port2 in another shell.  CTRL-C here when done.\n");
  65.         do
  66.         {                                                 /* port1 will wait forever and reply   */
  67.             signal = Wait(portsig | usersig);             /* to messages, until the user breaks. */
  68.  
  69.                                    /* Since we only have one port that might get messages we     */
  70.             if (signal & portsig)  /* have to reply to, it is not really necessary to test for   */
  71.             {                      /* the portsignal. If there is not message at the port, xymsg */
  72.  
  73.                 while(xymsg = (struct XYMessage *)GetMsg(xyport))        /* simply will be NULL. */
  74.                 {
  75.                     printf("port1 received: x = %d y = %d\n", xymsg->xy_X, xymsg->xy_Y);
  76.  
  77.                     xymsg->xy_X += 50;       /* Since we have not replied yet to the owner of    */
  78.                     xymsg->xy_Y += 50;       /* xymsg, we can change the data contents of xymsg. */
  79.  
  80.                     printf("port1 replying with: x = %d y = %d\n", xymsg->xy_X, xymsg->xy_Y);
  81.                     ReplyMsg((struct Message *)xymsg);
  82.                 }
  83.             }
  84.  
  85.             if (signal & usersig)                                    /* The user wants to abort. */
  86.             {
  87.                 while(xymsg = (struct XYMessage *)GetMsg(xyport))    /* Make sure port is empty. */
  88.                     ReplyMsg((struct Message *)xymsg);
  89.                 ABORT = TRUE;
  90.             }
  91.         }
  92.         while (ABORT == FALSE);
  93.             DeletePort(xyport);
  94.         }
  95.     else printf("Couldn't create 'xyport'\n");
  96. }